package com.cwd.arm.application.service.write;

import com.cwd.arm.application.dto.tax.TaxAddDto;
import com.cwd.arm.application.dto.tax.TaxUpdateDto;
import com.cwd.arm.application.service.write.facade.TaxWriteService;
import com.cwd.arm.domain.entity.TaxEntity;
import com.cwd.arm.domain.repository.TaxRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
* Description:开票信息
* Created on 2021年11月16日
* @author  yan
*/
@Repository
@Primary
public class TaxWriteServiceImpl implements TaxWriteService{

    @Autowired
    private TaxRepository taxRepository;

    @Transactional
    @Override
    public Long save(TaxAddDto addDto) {
        return taxRepository.save(convertToEntity(addDto));
    }

//    @Transactional
    @Override
    public void update(TaxUpdateDto updateDto) {
        taxRepository.updateCaseChangeReceiveNode(convertToEntity(updateDto));
    }

    @Override
    public void del(Long id) {
        taxRepository.del(id);
    }

    private TaxEntity convertToEntity(TaxAddDto dto){
        TaxEntity taxEntity = new TaxEntity();
        BeanUtils.copyProperties(dto,taxEntity);
        return taxEntity;
    }

    private TaxEntity convertToEntity(TaxUpdateDto dto){
        TaxEntity taxEntity = new TaxEntity();
        BeanUtils.copyProperties(dto,taxEntity);
        return taxEntity;
    }
}
